package com.example.androidstart.homepage.viewholder;

import static com.example.androidstart.homepage.util.HttpUtil.requestImg;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.appcompat.content.res.AppCompatResources;

import com.example.androidstart.R;
import com.example.androidstart.homepage.CustomViewHolder;
import com.example.androidstart.homepage.IViewHolderCreator;
import com.example.androidstart.homepage.item.ImageItemInfo;

// https://blog.csdn.net/qq_52815083/article/details/124146370
public class HeaderImgViewHolder extends CustomViewHolder<ImageItemInfo> {
    private HeaderImgViewHolder(@NonNull View itemView) {
        super(itemView);
    }


    public static final IViewHolderCreator<HeaderImgViewHolder> CREATOR = new IViewHolderCreator<HeaderImgViewHolder>() {
        @Override
        public HeaderImgViewHolder createViewHolder(View itemView) {
            return new HeaderImgViewHolder(itemView);
        }

        @Override
        public int getLayoutId() {
            return R.layout.homepage_img_layout;
        }
    };

    private ImageView mHpgImg;

    @Override
    public void initView() {
        super.initView();
        // 可以可以执行创建view后的初始化操作
        mHpgImg = itemView.findViewById(R.id.hpg_img);
    }

    @Override
    public void onBind(ImageItemInfo imageItemInfo) {
        super.onBind(imageItemInfo);
        int imgID = imageItemInfo.getItemInfo();
        mHpgImg.setImageDrawable(AppCompatResources.getDrawable(itemView.getContext(), imgID));
    }
}
